// 是否为空
const isNull = function (value) {
    if (value === null) {
        return true;
    }
    if (value === undefined) {
        return true;
    }
    return false;
};

// 是否为空白
const isBlank = function (value) {
    if (isNull(value)) {
        return true;
    }
    if (value === "") {
        return true;
    }
    return false;
};

const msg = function (msg) {
    alert(msg);
};

// 获取dom对象
const get = function (obj) {
    return document.querySelector(obj);
};

// 获取text内容
const getText = function (target) {
    return target.innerText;
};

// 获取text内容
const setText = function (target, content) {
    return target.innerText = content;
};

// 倒计时
const timeout = function (_this, times) {
    if (_this.com_timeoutFlg === true) {
        let time = times;
        _this.com_timeoutDes = `获取验证码(${time})`;
        var timer = setInterval(() => {
            time--;
            _this.com_timeoutDes = `获取验证码(${time})`;
            if (time == 0) {
                clearInterval(timer);
                _this.com_timeoutDes = `获取验证码`;
                _this.com_timeoutFlg = true;
            }
        }, 1000);
        _this.com_timeoutFlg = false;
    }
};

const doTimeout = function (obj, text, times) {
    setText(obj, text + "(" + times + ")");
    times = times - 1;
};

export default function (Vue) {
    //添加全局API
    Vue.prototype.$common = {
        timeout,
        get,
        getText,
        setText,
        isNull,
        isBlank,
        msg,
    }
}